package org.brisling.satisfaction.queryService;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.brisling.base.domain.ListDomain;
import org.brisling.base.service.AbstractBaseQueryService;
import org.brisling.common.ConstSysParam;
import org.brisling.satisfaction.domain.SatisfactionEvaluateMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController 
@RequestMapping("/satisfactionEvaluateMessage/query")

public class QuerySatisfactionEvaluateMessageService extends AbstractBaseQueryService<SatisfactionEvaluateMessage>{

	public QuerySatisfactionEvaluateMessageService(){
		this.moduleName = ConstSysParam.MODULE_SATISFACTION_EVALUATE_MESSAGE;
		this.subSystem = ConstSysParam.SUBSYSTEM_STATISFACTION;
		this.tableName = ConstSysParam.VIEW_PREFIX + this.moduleName;
		this.clazz = SatisfactionEvaluateMessage.class;	
		orderMap.put("evaluateat","desc");	
	}
	
	@PersistenceContext(unitName=ConstSysParam.SUBSYSTEM_SYSMAN)
	@Autowired
	protected void setEntityManager(EntityManager entityManager){
		this.entityManager = entityManager;		
	}
	
	public SatisfactionEvaluateMessage getOne(@RequestParam(value="id",required=false) Long id){
		return super.getOneByIdentify("id", id.toString());		
	}
	
	/**
	 * 根据用户唯一编码查找用户信息
	 * @param identify	用户唯一编码
	 * @return 用户信息记录
	 */
	@RequestMapping("/getOneByIdentify.action")
	public SatisfactionEvaluateMessage getOneByIdentify(@RequestParam(value="identify",required=false) String identify){	
		return super.getOneByIdentify(identify);
	}
	
	/**
	 * 根据部门id查找用户集合
	 * @param page	页码
	 * @param rows	行数
	 * @param deptid	部门编码
	 * @return	用户数据集
	 */
	@RequestMapping("/getUserByDeptid.action")
	public ListDomain<SatisfactionEvaluateMessage> getSatisfactionEvaluateMessageByDept(@RequestParam(value="page",required=false) Integer page,
			@RequestParam(value="rows",required=false) Integer rows,
			@RequestParam(value="deptid",required=false) Long deptid){
		
		String view_department = ConstSysParam.VIEW_PREFIX + ConstSysParam.MODULE_DEPARTMENT;
		String sql = " SELECT u.* FROM %1$s u LEFT JOIN %2$s d ON u.deptid=d.deptid AND d.deptid=%3$d" ;
		sql= String.format(sql, ConstSysParam.VIEW_USER, view_department,deptid);		
		
		return super.getPagedListDomain(page, rows, sql);
	}
	
	public List<SatisfactionEvaluateMessage> getAllList(String sql) {
		return super.getAllList(sql);
	}	
	
}
